#include <iostream>
using namespace std;

class Marray
{
    int* array;
    int size;
public:
    Marray(int size){
        this ->size = size;
        array = new int[size];
    }


    ~Marray(){
        delete[] array;
    }


    int& operator[](int a){
        return array[a];
    }


    int getsize(){
        return size;
    }


    void add(int a)
    {
    int* tempArray = new int[size + 1];
    for (int i = 0; i < size; i++) {
        tempArray[i] = array[i];
    }
    tempArray[size] = a;
    delete[] array;
    array = tempArray;
    size++;
    }


    void modify (int a,int b)
    {
    if(a-1>=0&&a-1<size)
       array[a-1] = b;
    }


    void remove(int a )
    {
    if (a < 0 || a >= size) 
    {
        return;
    }
    int* tempArray = new int[size - 1];
    for (int i = 0, j = 0; i < size; i++) 
    {
        if (i != a-1) 
        {
            tempArray[j++] = array[i];
        }
    }
    delete[] array;
    array = tempArray;
    size--;
    }

    void log()
    {
        for (int i = 0;i<size;i++)
        {
            cout<< array[i]<<' ';
        }
        cout<< endl;
    }

    int getdata(int a){
        return array[a-1];
    }
};



int main()
{
    Marray MA(10);
    for(int i = 0;i<10;i++)
    {
        MA[i] = i+1;
    }
    MA.log();

    MA.add(20);
    MA.log();

    MA.modify(8,32);
    MA.log();

    MA.remove(3);
    MA.log();

    cout<<MA.getdata(6)<<endl;
}


